package cn.JHai.rbac.controller;


import cn.JHai.rbac.RequiredPermission;
import cn.JHai.rbac.domain.SystemDictionary;
import cn.JHai.rbac.query.PageResult;
import cn.JHai.rbac.query.QueryObject;
import cn.JHai.rbac.service.SystemDictionaryService;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("systemDictionary")
public class SystemDictionaryController {

    @Autowired
    SystemDictionaryService systemDictionaryService;

    /**
     * 显示systemDictionary，运用了分页
     * @param queryObject
     * @param model
     * @return
     */
    @RequestMapping("/list")
    @RequiredPermission({"获取字典","systemDictionary:list"})
    public String list(QueryObject queryObject , Model model){
        PageResult result = systemDictionaryService.query(queryObject);
        model.addAttribute("result",result);
        return "/systemDictionary/list";
    }


    @RequestMapping("saveOrUpdate")
    @RequiredPermission({"更新和添加字典","systemDictionary:saveOrUpdate"})
    public String saveOrUpdate(SystemDictionary systemDictionary){
        systemDictionaryService.saveOrUpdata(systemDictionary);
        return "redirect:/systemDictionary/list";
    }
}
